package com.hdsx.netty.tomcatserver.nio;

import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author 占贤银
 * time 2024/8/5 21:14
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public class XYResponse {

    private SocketChannel socketChannel;

    public XYResponse(SocketChannel socketChannel) {
        this.socketChannel = socketChannel;
    }

    public void write(String context) {
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("HTTP/1.1 200 OK \n");
            sb.append("Content-Type:text/html;charset=utf-8 \n");
            sb.append("\r\n");
            sb.append(context);
            this.socketChannel.write(ByteBuffer.wrap(sb.toString().getBytes()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
